﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;

namespace SGP.Common
{
    public sealed class NhibernateHelper
    {
        private static ISession session;

        private NhibernateHelper()
        {

        }

        public static ISession GetCurrentSession()
        {
            if (session == null)
            {
                Configuration cfg = new Configuration();
                cfg.AddAssembly("SGP.Nhibernate.Model");
                ISessionFactory sessionFactory = cfg.BuildSessionFactory();
                session = sessionFactory.OpenSession();

                return session;
            }

            return session;
        }

        public static void CloseSession()
        {
            if(session == null)
                return;
            session.Close();
        }
    }
}
